<template>
	<view class="">
		<view class="top1">
			<p style="text-align: center; font-size: 33px;color: white;">{{type_name}}</p>
		</view>
		<view class="uni-form-item uni-column" style="width: 80%; margin:5% auto 0 auto;">
			<view class="title">意见反馈主题<span style="color: red;">*</span></view>
			<input class="uni-input" style="border: 1px solid #6a6a6a;border-radius: 5px; background: #f1f1f1;" disabled="true" v-model="post.title" placeholder="输入标题" />
		</view>
		<hr style="margin-top: 2%;width: 90%;margin-left: auto;margin-right: auto;"/>
		<view class="uni-form-item uni-column" style="width: 80%; margin:5% auto 0 auto;">
			<view class="title">意见反馈内容<span style="color: red;">*</span></view>
			<view class="uni-textarea" style="border: 1px solid #6a6a6a;border-radius: 5px; background: #f1f1f1;">
			<textarea @blur="bindTextAreaBlur" v-model="post.content" placeholder="输入内容" disabled="true"/>
			</view>
		</view>
		<hr style="margin-top: 2%;width: 90%;margin-left: auto;margin-right: auto;"/>
		<view class="uni-form-item uni-column" style="width: 80%; margin:3% auto 0 auto;"  v-if="post.img_src!=''">
			<view class="title">图片<span style="color: red;">*</span></view>
			<image  mode="aspectFit" style="width: 90%; margin: -5% auto 0 auto;" :src="post.img_src"></image>
		</view>
		<hr style="margin-top: 2%;width: 90%;margin-left: auto;margin-right: auto;"/>
		<view class="uni-form-item uni-column" style="width: 80%; margin:0% auto 0 auto;" v-if="post.name!=''">
			<view class="title">联系方式<span style="color: red;">*</span></view>
		</view>
		<view class="uni-form-item uni-column" style="width: 80%; margin:0 auto 0 auto;" v-if="post.name!=''">
			<view class="" style="display: flex;">
				<label >姓名</label>
				<label style="margin-left: 5%;">联系方式</label>
				<label  style="margin-left: 15%;">身份</label>
			</view>
			<view class="" style="display: flex;">
				<input class="uni-input" v-model="post.name" style="border: 1px solid #6a6a6a;border-radius: 5px; background: #f1f1f1; font-size: 12px; width: 20%;"  disabled="true"/>
				<input class="uni-input" v-model="post.phone" style="border: 1px solid #6a6a6a;border-radius: 5px; background: #f1f1f1;font-size: 12px; width: 30%; margin-left: 5%;"   disabled="true"/>
				<input class="uni-input" v-model="post.identity" style="border: 1px solid #6a6a6a;border-radius: 5px; background: #f1f1f1; font-size: 12px; width: 30%; margin-left: 5%;"  disabled="true"/>
				<!-- <input class="uni-input" style="border: 1px solid black;border-radius: 5px; font-size: 12px; width: 25%; margin-left: 15%;"  placeholder="请输入" /> -->
			</view>
		</view>
		<hr style="margin-top: 2%;width: 90%;margin-left: auto;margin-right: auto;"/>
		<view class="uni-form-item uni-column" style="width: 80%; margin:0 auto 0 auto;" v-if="post.reply==''&&user_info.type=='leader'">
			<view class="title">回复：</view>
			<view class="uni-textarea" style="border: 1px solid black;">
			<textarea  placeholder="输入内容" v-model="reply"/>
			</view>
		</view>
		<view class="a">
			<button @tap="postComment" v-if="post.reply==''&&user_info.type=='leader'">回复</button>
		</view>
		<view class="uni-form-item uni-column" style="width: 80%; margin:-5% auto 0 auto;" v-if="post.reply!=''">
			<view class="title">{{post.leader_info}}&nbsp;&nbsp;&nbsp;&nbsp;回复：</view>
			<view class="uni-textarea" style="border: 1px solid #6a6a6a;border-radius: 5px; background: #f1f1f1;">
			<textarea  placeholder="输入内容" v-model="post.reply" disabled="true"/>
			</view>
		</view>
<!-- 		<view class="uni-padding-wrap uni-common-mt" style="width: 30%; margin: 5% auto 0 40%;">
			<button @tap="post"  type="primary" size="mini">提交</button>
		</view> -->
		<popview4 ref="popview4"></popview4>
		<loading
			ref="loading"
			:custom="false"
			:shadeClick="true"
			:type="1"
			>
			<view style="text-align: center;">等待中</view>
		</loading>
	</view>
</template>

<script>
	import popview4 from '@/components/pop-view/pop-view4.vue'
	import loading from '@/components/xuan-loading/xuan-loading.vue'
	export default {
		components: {
			popview4,
			loading
		},
		async onLoad(option){
			let item = JSON.parse(decodeURIComponent(option.item));
			this.type_name=option.type_name
			let value = await uni.getStorageSync('user_info');
			this.user_info=value
			this.author=item.user_info.nick_name
			let a = await this.getPostByPostIdB(item._id)
		},
		data() {
			return {
				post:{},
				nick_name:"",
				type_name:"",
				author:"",
				reply:"",
				list:[
					{
						"title":"评论1",
						"content":"无",
						"date":"2020-02-02 20:20",
						"author":"eweew"
					},
					{
						"title":"评论2",
						"content":"无",
						"date":"2020-02-02 20:20",
						"author":"eweew"
					},
					{
						"title":"评论3",
						"content":"无",
						"date":"2020-02-02 20:20",
						"author":"eweew"
					}
				],
				comment:"",
				user_info:{}
			}
		},
		methods: {
			postComment(){
				if(this.reply==0){
					this.$refs['popview4'].error('请输入评论');
				}else{
					this.$refs.loading.open();
					// let comment_info={
					// 	"reply":this.comment,
					// 	"leader_info":this.user_info,
					// }
					let info={
							"post_id":this.post._id,
							"reply":this.reply,
							"leader_info":this.user_info,
						}
						console.log(info)
					uniCloud.callFunction({
					    name: 'postComment',
					    data: {
							"post_id":this.post._id,
							"reply":this.reply,
							"leader_info":this.user_info.nick_name,
						}
					  })
					  .then(res => {
						let result=res.result
						// this.$refs.loading.close();
						console.log(result)
						//this.$refs['popview4'].success('评论成功');
						this.getPostByPostId(this.post._id)
					  });
				}				
			},
			getPostByPostId(id){
				uniCloud.callFunction({
					name: 'getPostById',
					data: {
							"post_id":id,
					}
				})
				.then(res => {
					let result=res.result
						// this.$refs.loading.close();
					this.post=result.post
					this.$refs.loading.close();
					this.$refs['popview4'].success('回复成功');
					this.comment=""
				});
			
			},
			getPostByPostIdB(id){
				uniCloud.callFunction({
					name: 'getPostById',
					data: {
							"post_id":id,
					}
				})
				.then(res => {
					let result=res.result
						// this.$refs.loading.close();
					this.post=result.post
					console.log(this.post)
				});
			
			},
			getTime(){
				var date = new Date(),
				year = date.getFullYear(),
				month = date.getMonth() + 1,
				day = date.getDate(),
				hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
				minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
				second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				month >= 1 && month <= 9 ? (month = "0" + month) : "";
				day >= 0 && day <= 9 ? (day = "0" + day) : "";
				var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
				return timer;
			}
		}
	}
</script>

<style scoped>
	.top1{
		width: 100%;
		height: 20vh;
		padding-top: 10vh;
/* 		background: rgba(13, 58, 117, 0.4); */
		background-image: url('https://mp-7bc5dd24-82e9-4518-a7c3-a50a8769ed47.cdn.bspapp.com/cloudstorage/微信图片_20250108155202.jpg');
	}
	.a{
		display: flex;
		margin-top: 5%;
	}
	radio-group label:nth-child(2){
		margin-left: 10%;
	}
</style>
